package fr.vincent.aquarium.metier.poisson;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import fr.vincent.aquarium.metier.animal.Animal;

@Entity
@Table(name = "Poisson")
public class Poisson extends Animal implements Serializable {

	private static final long serialVersionUID = -409733265964246464L;

	private Long id;
	private double ph;
	private double temperature;
	private String placement;
	private double durete;
	private String famille;

	private List<Poisson> listePoissonsIncompatibles;

	public Poisson() {
	}

	public Poisson(Long id, double ph, double temperature, String placement,
			double durete, List<Poisson> listePoissonsIncompatibles) {
		super();
		this.id = id;
		this.ph = ph;
		this.temperature = temperature;
		this.placement = placement;
		this.durete = durete;
		this.listePoissonsIncompatibles = listePoissonsIncompatibles;
	}

	public boolean estCompatible(Poisson unAutrePoisson){		
		for(Poisson poisson : this.listePoissonsIncompatibles){
			if(poisson.equals(unAutrePoisson))
				return false;
		}
		
		return true;
	}
	
	@Override
	public String toString() {
		return "Poisson [id=" + id + ", ph=" + ph + ", temperature="
				+ temperature + ", placement=" + placement + ", durete="
				+ durete + ", listePoissonsIncompatibles="
				+ listePoissonsIncompatibles + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(durete);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime
				* result
				+ ((listePoissonsIncompatibles == null) ? 0
						: listePoissonsIncompatibles.hashCode());
		temp = Double.doubleToLongBits(ph);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result
				+ ((placement == null) ? 0 : placement.hashCode());
		temp = Double.doubleToLongBits(temperature);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Poisson other = (Poisson) obj;
		if (Double.doubleToLongBits(durete) != Double
				.doubleToLongBits(other.durete))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (listePoissonsIncompatibles == null) {
			if (other.listePoissonsIncompatibles != null)
				return false;
		} else if (!listePoissonsIncompatibles
				.equals(other.listePoissonsIncompatibles))
			return false;
		if (Double.doubleToLongBits(ph) != Double.doubleToLongBits(other.ph))
			return false;
		if (placement == null) {
			if (other.placement != null)
				return false;
		} else if (!placement.equals(other.placement))
			return false;
		if (Double.doubleToLongBits(temperature) != Double
				.doubleToLongBits(other.temperature))
			return false;
		return true;
	}

	@Id
	@GeneratedValue
	@Column(name = "id")
	public Long getId() {
		return this.id;
	}

	@Column(name = "ph", nullable = false)
	public double getPh() {
		return ph;
	}

	public void setPh(double ph) {
		this.ph = ph;
	}

	@Column(name = "temperature", nullable = false)
	public double getTemperature() {
		return temperature;
	}

	public void setTemperature(double temperature) {
		this.temperature = temperature;
	}

	@Column(name = "placement", nullable = false)
	public String getPlacemet() {
		return placement;
	}

	public void setPlacement(String placement) {
		this.placement = placement;
	}

	@Column(name = "durete", nullable = false)
	public double getDurete() {
		return durete;
	}

	public void setDurete(double durete) {
		this.durete = durete;
	}
	
	@Column(name = "famille", nullable = false)
	public String getFamille() {
		return famille;
	}

	public void setFamille(String famille) {
		this.famille = famille;
	}
	
	

	@ManyToMany(targetEntity = Poisson.class)
	public List<Poisson> getListePoissonsIncompatibles() {
		return listePoissonsIncompatibles;
	}

	public void setListePoissonsIncompatibles(
			List<Poisson> listePoissonsIncompatibles) {
		this.listePoissonsIncompatibles = listePoissonsIncompatibles;
	}

}
